package ym.ecrm.web.action.systemManagement;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import ym.ecrm.core.common.exception.MessageException;
import ym.ecrm.core.dto.systemManagement.UserDTO;
import ym.ecrm.core.service.systemManagement.ISystemService;
import ym.ecrm.web.action.base.BaseAction;

import com.opensymphony.xwork2.ActionContext;

/**
 * 
 * @author Princess
 * 
 */
@Controller
public class ChangePasswordAction extends BaseAction{

	private String password;
	private String newPassword;
	
	@Autowired
	private ISystemService systemService;
	
	public String execute() throws Exception {
		UserDTO user = (UserDTO) ActionContext.getContext().getSession().get("user");
		if(user.getUserId() != null){
			if(systemService.loadUser(user.getUserId()).getPassword().equals(password)){
				systemService.changePassword(user.getUserId(), newPassword);
				return proccess();
			}
			return processException(new MessageException("原密码错误"));
		}else {
			return processException(new MessageException("登陆超时，请重新登陆"));
		}
	}
	
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNewPassword() {
		return newPassword;
	}

	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}



	public String getErrorMessage(){
		return errorMessage;
	}
	
	public String getSuccess(){
		return success;
	}

}
